<template>
  <div>
    <statement-select-view ref="statementSelectView" :data-list="tabList" @onShowPreview="onShowPreview" />
    <statement-select-drawer ref="statementSelectDrawer" />
  </div>
</template>
<script>
import { getBsDataReport } from "@/api/syrw/bsDataReport";
import StatementSelectView from "@/views/reportForms/components/StatementSelectView.vue";
import StatementSelectDrawer from "@/views/reportForms/components/StatementSelectDrawer.vue";
export default {
  name: "bsDataReportExport",
  components: {
    StatementSelectView,
    StatementSelectDrawer
  },
  data() {
    return {
      form: {},
      tabList: []
    };
  },
  created() {},
  mounted() {},
  methods: {
    async init(reportId) {
      const response = await getBsDataReport(reportId);
      this.form = response.data;
      if (!this.form.excelTypeList || this.form.excelTypeList.length == 0) {
        this.$message.warning("该试验任务没有报表，请查证后再进行操作！");
        return;
      }
      let tabList = [];
      let excelTypeMap = {};
      this.form.excelTypeList.forEach((item) => {
        // 是否包含label
        if (excelTypeMap.hasOwnProperty(item.label)) {
          excelTypeMap[item.label].push(item.excelId);
        } else {
          excelTypeMap[item.label] = [item.excelId];
          tabList.push({
            val: item.label,
            name: item.excelTypeName
          });
        }
      });
      this.tabList = tabList;
      this.$refs.statementSelectView.init();
    },
    //预览
    onShowPreview(tableList) {
      if (!tableList || tableList.length <= 0) {
        return;
      }
      let arr = [];
      this.form.excelTypeList.forEach((item) => {
        if (tableList.includes(item.label)) {
          arr.push({ label: item.label, excelId: item.excelId, syType: this.form.syType, typeSort: item.typeSort });
        }
      });
      this.$refs.statementSelectDrawer.init(arr);
    }
  }
};
</script>
<style lang="scss" scoped></style>
